import os
from datetime import datetime
from role_play_core.writer import Writer


OUTPUT_DIR = 'output/'
if not os.path.exists(OUTPUT_DIR):
    os.mkdir(OUTPUT_DIR)

class MsgToFileWriter(Writer):

    def write(self, data) -> str:

        level_dir = os.path.join(OUTPUT_DIR, datetime.now().strftime('%Y-%m-%d'))
        if not os.path.exists(level_dir): os.mkdir(level_dir)

        filename = os.path.join(level_dir, datetime.now().strftime('%H-%M-%S'))

        with open(f"{filename}.txt",'x') as f:
            f.write("".join(item['content'] for item in data))
        return filename

